﻿@model dynamic
@{
    ViewData["Title"] = Model.title;
}

<div class="mini-toolbar" style="padding:2px;border-bottom:0;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a id="a_add" plain="true" class="mini-button" iconcls="icon-save" title="保存" onclick="saveClick">保存</a>
                <a id="a_del" plain="true" class="mini-button" iconcls="icon-cancel" title="关闭" onclick="cancelClick">关闭</a>  
            </td>
        </tr>
    </table>
</div>
<div style="padding:2px;border-bottom:0;">
    <form id="frmEdit" method="post" action="">
        <input type="hidden" class="mini-hidden" name="user_id" value="@Model.user_id" id="user_id" />
        <div id="tabs1" class="mini-tabs"  activeIndex="0" style="width:100%;height:100%;min-height:400px;" bodyStyle="padding:0;border:0;">
            <div title="用户角色">
                用户角色:   <div id="userRole" class="mini-combobox" style="width:100%;" textField="name" valueField="role_id"
                            url="/sys/user/GetUserRole4Edit?id=@Model.user_id" value="@Model.user_roles" multiSelect="true">
                </div>
            </div>
            <div title="用户菜单"  >
                <ul id="trMenu" class="mini-tree" url="/sys/user/GetUserMenu4Edit?id=@Model.user_id" style="width:200px;padding:5px;"
                    showTreeIcon="true" textField="name" idField="menu_id" parentField="parent_id" resultAsTree="false"
                    showCheckBox="true" allowSelect="false" enableHotTrack="false"
                    checkRecursive="false" autoCheckParent="false" onnodecheck="onMenuChecked"></ul>
            </div> 
        </div>
        
    </form>
</div>
<script type="text/javascript">
        mini.parse();
        function closeClick() {
            sx.winClose({ sucess: true });
        }
        function cancelClick() {
            sx.winCancel();
        }
        function saveClick() { 
            var tree = mini.get("trMenu");
            var value = tree.getValue(true);
            $.ajax({
                url: "/sys/User/SaveUserAuthAjax",
                type: "post",
                data: {
                    user_id: mini.get("user_id").getValue(),
                    role_ids: mini.get("userRole").getValue(),
                    menu_ids: value,
                },
                dataType:"json",
                success: function (data) {
                    if (data.resultCode == sx.resultCode.ok) {
                        sx.success("保存成功！", function () { closeClick(); });
                    } else {
                        sx.error(data.info);
                    }
                }
            });
        }

        // 如果子节点选中， 则选中父节点
        function onMenuChecked(e) {
            var menu = e.sender;
            var node = e.node;
            if (node.checked) {
                checkParentNode(menu, node.parent_id);
            }
        }
        function checkParentNode(menu, pid) {
            var pnode = menu.getNodesByValue(pid);
            if (pnode.length > 0) {
                menu.checkNode(pnode[0]);
                checkParentNode(menu, pnode[0].parent_id);
            }
        }
</script> 